package com.leetcode.p200;

import com.bean.TreeNode;
import com.utils.TreeUtils;

public class Test226 {

    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        help(root);

        return root;
    }

    private void help(TreeNode root) {
        if (root == null) {
            return;
        }
        TreeNode leftNode = root.left;
        TreeNode rightNode = root.right;

        root.left = rightNode;
        root.right = leftNode;

        help(root.left);
        help(root.right);
    }

    public static void main(String[] args) {
        TreeNode root = TreeUtils.buildTree();
        TreeUtils.showTree(root);

        Test226 test = new Test226();
        TreeNode result = test.invertTree(root);
        TreeUtils.showTree(result);
    }

}
